// Audio.h provides the attributes of the Audio class
//-----------------

#if !defined( AudioH)
#define AudioH

// for infinite looping of audio
#define INFINITE_LOOP -1

//-----------------
// Includes various libraries and files
#include <cassert>			// for asserts
#include <d3dx9.h>			// for vectors
#include <fmod.hpp>			// for all audio functions
#include <fmod_errors.h>	// to catch error from FMOD
#include <string>			// for file names
#include <sstream>			// used to concatonate strings to create file locations

//-----------------

// class defining fmod exceptions for the sound system
class fmod_exception : public std::exception {};

class Audio {
	public:
		// constructors and destructor
		Audio();
		Audio( const std::string& filename, const int loop_count);
		Audio( const Audio& a);
		~Audio();

		// accessors
		bool is_playing() const;
		bool is_mute() const;

		// mutators
		void create_3d_sound( const float& x, const float& y, const float& z);
		void create_3d_sound( const float& x, const float& y, const float& z, const std::string& filename, int loop_count);
		void create_sound();
		void create_sound( const std::string& filename, int loop_count);
		void set_pos( const float& x, const float& y, const float& z);
		void set_filename( const std::string& fn);

		void update_channels();
		void play();
		void pause();
		void stop();
		void set_play_pos( const int s);
		void mute();
		void unmute();

	private:
		void fmod_assert( FMOD_RESULT result);		// used to catch errors from FMOD
		
		int loop_count_;							// how many times the sound clip will loop
		FMOD::System *g_system_;					// pointer to the audio system
		std::string filename_;						// filename of the audio file
		D3DXVECTOR3 pos_;							// position of the sound in 3D space
		FMOD::Sound* sound_;						// pointer to the sound
		FMOD::Channel* channel_;					// pointer to the channel currently being played
		bool mute_;									// bool for if the sound is muted or not
};

#endif